﻿#include "crypto.h"

Crypto::Crypto()
{

}
QString Crypto::plain2Cipher(QString plainText){
    QString cipherText;

    QAESEncryption encryption(_aes, _mode, _padding);
    QByteArray hashKey = QCryptographicHash::hash(_key.toUtf8(), QCryptographicHash::Md5);

    QByteArray encodedText = encryption.encode(plainText.toUtf8(), hashKey);
    cipherText = QString::fromLatin1(encodedText.toBase64());

    return cipherText;
}


QString Crypto::cipher2Plain(QString cipherText){

    QString plainText;

    QAESEncryption encryption(_aes, _mode, _padding);
    QByteArray hashKey = QCryptographicHash::hash(_key.toUtf8(), QCryptographicHash::Md5);

    QByteArray decodedText = encryption.decode(QByteArray::fromBase64(cipherText.toLatin1()), hashKey);
    plainText = QString::fromUtf8(decodedText);

    return plainText;
}

